/*     */ package com.hp.bon.logreverse.perf;
/*     */ 
/*     */ import com.hp.bon.logreverse.BaseMsgProcess;
/*     */ import com.hp.bon.logreverse.MsgInfo;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ public class PerfTestProcess extends BaseMsgProcess
/*     */ {
/*  14 */   private static final Logger LOG = LoggerFactory.getLogger(PerfTestProcess.class);
/*     */ 
/*  16 */   TrafficGenThread trafficGenThread = new TrafficGenThread("TrafficGenThread");
/*     */ 
/*  55 */   protected volatile int capsTarget = 20;
/*  56 */   private static int BUFFER_MAX_NUM = 2048;
/*  57 */   public ArrayList<Object> logObjectBuffer = new ArrayList(BUFFER_MAX_NUM);
/*     */ 
/*  59 */   int intervalIncrease = 100;
/*     */ 
/*     */   public PerfTestProcess()
/*     */   {
/*  18 */     this.trafficGenThread.start();
/*     */   }
/*     */ 
/*     */   public void stop()
/*     */   {
/*  23 */     LOG.info("TrafficGenThread stopped");
/*  24 */     this.trafficGenThread.stop();
/*     */   }
/*     */ 
/*     */   public boolean processMsg(MsgInfo msgInfo)
/*     */   {
/*  29 */     Object msg = msgInfo.getMsg();
/*  30 */     boolean isBusy = false;
/*     */     do {
/*  32 */       synchronized (this.logObjectBuffer)
/*     */       {
/*  35 */         if (this.logObjectBuffer.size() < this.capsTarget << 1)
/*     */         {
/*  37 */           this.logObjectBuffer.add(msg);
/*  38 */           break;
/*     */         }
/*     */ 
/*  42 */         isBusy = true;
/*     */       }
/*     */ 
/*     */       try
/*     */       {
/*  47 */         Thread.sleep(100L);
/*     */       }
/*     */       catch (InterruptedException e) {
/*  50 */         e.printStackTrace();
/*     */       }
/*     */     }
/*  31 */     while (
/*  52 */       isBusy);
/*  53 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean doCapsOperate(List<Object> tempList, int beginIdx, int endIdx, boolean isLog)
/*     */   {
/* 135 */     for (int i = beginIdx; i < endIdx; i++) {
/* 136 */       tempList.get(i);
/*     */     }
/* 138 */     if ((endIdx - beginIdx > 0) && (isLog))
/*     */     {
/* 140 */       LOG.info("doOperate num = " + (endIdx - beginIdx) + ",object=" + tempList.get(endIdx - 1));
/*     */     }
/* 142 */     return true;
/*     */   }
/*     */   public void setCaps(int caps) {
/* 145 */     if (caps >= 10)
/*     */     {
/* 147 */       this.capsTarget = caps;
/* 148 */       this.intervalIncrease = 100;
/*     */     }
/*     */     else
/*     */     {
/* 152 */       this.capsTarget = caps;
/* 153 */       this.intervalIncrease = 1000;
/*     */     }
/*     */   }
/*     */ 
/*     */   private class TrafficGenThread extends Thread
/*     */   {
/*  65 */     List<Object> tempList = new ArrayList(PerfTestProcess.BUFFER_MAX_NUM);
/*  66 */     int idxInTemp = 0;
/*     */ 
/*     */     public TrafficGenThread(String name)
/*     */     {
/*  62 */       super();
/*     */     }
/*     */ 
/*     */     public void run()
/*     */     {
/*  70 */       long lastTime = System.currentTimeMillis();
/*  71 */       int count = 0;
/*     */       while (true) {
/*  73 */         long _t0 = System.currentTimeMillis();
/*  74 */         long step = _t0 - lastTime;
/*     */ 
/*  76 */         int operateNum = 0;
/*     */ 
/*  78 */         if (step > PerfTestProcess.this.intervalIncrease) {
/*  79 */           lastTime = _t0;
/*  80 */           operateNum = (int)(PerfTestProcess.this.capsTarget * step / 1000L);
/*  81 */           count++;
/*     */ 
/*  83 */           doOperate(operateNum, (count & 0x1FF) == 511);
/*     */         }
/*     */         try {
/*  86 */           Thread.sleep(10L);
/*     */         }
/*     */         catch (InterruptedException e1) {
/*  89 */           e1.printStackTrace();
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/*     */     private void doOperate(int operateNum, boolean isLog) {
/*  95 */       int beginIdx = this.idxInTemp;
/*  96 */       int endIdx = this.idxInTemp + operateNum;
/*  97 */       if (this.tempList.size() <= endIdx) {
/*  98 */         if (PerfTestProcess.this.logObjectBuffer.size() > 0)
/*     */         {
/* 100 */           ArrayList tempList2 = new ArrayList(64);
/* 101 */           for (int i = this.idxInTemp; i < this.tempList.size(); i++) {
/* 102 */             tempList2.add(this.tempList.get(i));
/*     */           }
/* 104 */           this.tempList.clear();
/* 105 */           this.tempList.addAll(tempList2);
/*     */ 
/* 108 */           synchronized (PerfTestProcess.this.logObjectBuffer) {
/* 109 */             this.tempList.addAll(PerfTestProcess.this.logObjectBuffer);
/* 110 */             PerfTestProcess.this.logObjectBuffer.clear();
/*     */           }
/*     */ 
/* 114 */           beginIdx = 0;
/* 115 */           endIdx = operateNum < this.tempList.size() ? operateNum : this.tempList.size();
/*     */         } else {
/* 117 */           endIdx = this.tempList.size();
/*     */         }
/*     */       }
/* 120 */       if (PerfTestProcess.this.doCapsOperate(this.tempList, beginIdx, endIdx, isLog))
/*     */       {
/* 122 */         this.idxInTemp = endIdx;
/*     */       }
/*     */       else
/*     */       {
/* 126 */         this.idxInTemp = beginIdx;
/*     */       }
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.logreverse.perf.PerfTestProcess
 * JD-Core Version:    0.6.1
 */